package com.wyvoid.forum.web.action;

import net.sourceforge.stripes.action.*;
import net.sourceforge.stripes.util.Log;
import com.wyvoid.forum.web.MyActionBeanContext;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

/**
 * User: cjp
 * Date: 2006-7-19
 * Time: 22:10:40
 */
public class BaseAction implements ActionBean {
    protected Log log = Log.getInstance(getClass());
    protected MyActionBeanContext context;

    public void setContext(ActionBeanContext actionBeanContext) {
        this.context = (MyActionBeanContext) actionBeanContext;
    }

    public MyActionBeanContext getContext() {
        return this.context;
    }

    @DontValidate
    public Resolution getBBSResolution(String view) {
        return new ForwardResolution("/WEB-INF/view/bbs/" + view + ".jsp");
    }

    @DontValidate
    public Resolution getAdminResolution(String view) {
        return new ForwardResolution("/WEB-INF/view/admin/" + view + ".jsp");
    }

    protected String getForwardUrl() {
        HttpServletRequest request = context.getRequest();
        String forward = request.getRequestURL().toString();
        if (StringUtils.isBlank(forward)) {
            forward = request.getHeader("referer");
        }
        return forward;
    }
}
